package org.jeecg.modules.health_code.controller;

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class test {
    public static void main(String[] args) {
        // 1. 替换为你的apiclient_cert.pem文件路径（绝对路径或相对路径）
        String certFilePath = "C:/web_serverah/apiclient_cert.pem";

        try (InputStream inputStream = new FileInputStream(certFilePath)) {
            // 2. 解析证书
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(inputStream);

            // 3. 提取序列号（转换为16进制字符串，大写）
            String serialNumber = cert.getSerialNumber().toString(16).toUpperCase();

            // 4. 输出结果
            System.out.println("证书序列号：" + serialNumber);
            System.out.println("请将此序列号填入微信支付配置中的serial_no字段");
        } catch (Exception e) {
            System.err.println("提取序列号失败：" + e.getMessage());
            e.printStackTrace();
        }
    }
}
